/*
 * @Author: Sonui
 * @Date: 2022-02-23 04:46:24
 * @LastEditors: Sonui
 * @LastEditTime: 2022-02-23 06:32:48
 * @FilePath: \AI_SCHEDULE\Timer.js
 * @Description: 获取教务处上课时间配置
 * email: me@sonui.cn
 * Copyright (c) 2022 by Sonui, All Rights Reserved. 
 */

/**
 * @description: 时间配置函数，此为入口函数，不要改动函数名
 * @param {*}
 * @return {*}
 */
async function scheduleTimer({
    providerRes,
    parserRes
} = {}) {
    let response,
        ret = {
            totalWeek: 0, //总周数：[1, 30]之间的整数
            startSemester: '', //开学时间：时间戳，13位长度字符串，推荐用代码生成
            startWithSunday: false, //是否是周日为起始日，该选项为true时，会开启显示周末选项
            showWeekend: true, //是否显示周末
            forenoon: 4, //上午课程节数：[1, 10]之间的整数
            afternoon: 4, //下午课程节数：[0, 10]之间的整数
            night: 2, //晚间课程节数：[0, 10]之间的整数
            sections: [{
                section: 1, //节次：[1, 30]之间的整数
                startTime: '08:00', //开始时间：参照这个标准格式5位长度字符串
                endTime: '08:50', //结束时间：同上
            }], //课程时间表，注意：总长度要和上边配置的节数加和对齐
        };
    response = await fetch("http://110.16.109.224:82/ajax/getSectionAndTime", {
        "headers": {
            "accept": "application/json, text/javascript, */*; q=0.01",
            "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
            "cache-control": "no-cache",
            "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
            "pragma": "no-cache",
            "proxy-connection": "keep-alive",
            "x-requested-with": "XMLHttpRequest"
        },
        "referrer": "http://110.16.109.224:82/student/teachingResources/classCurriculum/index",
        "referrerPolicy": "strict-origin-when-cross-origin",
        "body": "planNumber=&ff=f",
        "method": "POST",
        "mode": "cors",
        "credentials": "same-origin"
    });
    response = await response.text();
    response = JSON.parse(response);
    ret.totalWeek = response.section.zs;
    for (let i = 0; i < response.sectionTime.length; i++) {
        ret.sections[i] = {
            section: i + 1,
            startTime: response.sectionTime[i].startTime.substring(0, 2) + ':' + response.sectionTime[i].startTime.substring(2, 4),
            endTime: response.sectionTime[i].endTime.substring(0, 2) + ':' + response.sectionTime[i].endTime.substring(2, 4)
        };
    }
    return ret;
}